home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / global-one-water.swf / scripts / __Packages / Snd.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  3.3 KB  |  149 lines

  1. class Snd extends Sound
  2. {
  3.    var target;
  4.    var manager;
  5.    var _volume;
  6.    var onFadeComplete;
  7.    var fId;
  8.    static var FADE_RATE = 100;
  9.    function Snd(targ, sndman)
  10.    {
  11.       super(targ);
  12.       this.target = !targ ? _root : targ;
  13.       this.manager = sndman;
  14.       this._volume = super.getVolume();
  15.    }
  16.    function switchSound(id, loops)
  17.    {
  18.       var _loc3_ = this.position;
  19.       super.stop();
  20.       super.attachSound(id);
  21.       this.start(_loc3_ % this.duration / 1000,loops);
  22.    }
  23.    function fade(dVol, tVol, handler)
  24.    {
  25.       this.onFadeComplete = handler;
  26.       if(this.fId)
  27.       {
  28.          this.stopFade(this.fId);
  29.       }
  30.       this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,dVol * (Snd.FADE_RATE / 1000),tVol,true);
  31.    }
  32.    function fadeBy(dVol, t, handler)
  33.    {
  34.       this.onFadeComplete = handler;
  35.       if(this.fId)
  36.       {
  37.          this.stopFade(this.fId);
  38.       }
  39.       if(t > 0)
  40.       {
  41.          this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,dVol * (Snd.FADE_RATE / 1000),dVol * t,true);
  42.       }
  43.    }
  44.    function fadeTo(tVol, t, handler)
  45.    {
  46.       this.onFadeComplete = handler;
  47.       if(this.fId)
  48.       {
  49.          this.stopFade(this.fId);
  50.       }
  51.       if(t > 0)
  52.       {
  53.          var _loc3_ = (tVol - this.getVolume()) / t;
  54.          this.fId = setInterval(this,"changeVolTowards",Snd.FADE_RATE,_loc3_ * (Snd.FADE_RATE / 1000),tVol,true);
  55.       }
  56.       else
  57.       {
  58.          this.setVolume(tVol);
  59.       }
  60.    }
  61.    function changeVolTowards(dVol, tVol, fading)
  62.    {
  63.       var _loc2_ = this.getVolume();
  64.       if(Math.abs(dVol) < Math.abs(tVol - _loc2_))
  65.       {
  66.          this.changeVolume(dVol);
  67.       }
  68.       else
  69.       {
  70.          this.setVolume(tVol);
  71.          if(fading)
  72.          {
  73.             this.stopFade();
  74.          }
  75.       }
  76.    }
  77.    function stopFade()
  78.    {
  79.       if(this.fId)
  80.       {
  81.          clearInterval(this.fId);
  82.          delete this.fId;
  83.          this.onFadeComplete();
  84.          delete this.onFadeComplete;
  85.       }
  86.    }
  87.    function positionSound(a, d, f, t)
  88.    {
  89.       if(d < f)
  90.       {
  91.          t = !isNaN(t) ? (t >= 0 ? t : 0) : 100;
  92.          d = d >= 1 ? d : 1;
  93.          var _loc4_ = 1 / (d / f * 100);
  94.          this.setVolume(Math.ceil(_loc4_ * t));
  95.          this.setPan((- Math.sin(a)) * 100);
  96.       }
  97.       else
  98.       {
  99.          this.setVolume(0);
  100.       }
  101.    }
  102.    function positionSoundLinear(a, d, f, t)
  103.    {
  104.       if(d < f)
  105.       {
  106.          t = !isNaN(t) ? (t >= 0 ? t : 0) : 100;
  107.          this.setVolume((f - d) / f * t);
  108.          this.setPan((- Math.sin(a)) * 100);
  109.       }
  110.       else
  111.       {
  112.          this.setVolume(0);
  113.       }
  114.    }
  115.    function setVolume(n)
  116.    {
  117.       this._volume = n;
  118.       super.setVolume(n);
  119.    }
  120.    function getVolume()
  121.    {
  122.       return this._volume;
  123.    }
  124.    function changeVolume(n)
  125.    {
  126.       this.setVolume(this.getVolume() + n);
  127.    }
  128.    function remove()
  129.    {
  130.       super.stop();
  131.       delete this.manager.sounds[this.target.getDepth()];
  132.       this.target.removeMovieClip();
  133.       false;
  134.    }
  135.    function toString()
  136.    {
  137.       return "(target=" + this.target + ")";
  138.    }
  139.    function get volume()
  140.    {
  141.       return this._volume;
  142.    }
  143.    function set volume(n)
  144.    {
  145.       this._volume = n;
  146.       super.setVolume(n);
  147.    }
  148. }
  149.